<template>
    <div class="observer-lbrary-pages">
        <compSearchCriteria
         :formItem.sync="formItem" 
         @searchHandleChange="searchHandleChange" 
         v-model="dataTableConfig.requestParams"
         ref="refSearchCriteria"
         />
         <div class="btn-box" style="margin: 20px 0;">
            <div></div>
            <a-form layout="inline" style="display: flex;justify-content: flex-end;">
                <a-form-item>
                    <a-button class="blue-btn" type="primary" @click="increaseClick" icon>新增</a-button>
                </a-form-item>
                <a-form-item>
                    <a-button class="red-btn" type="primary" @click="batchDeletion" >批量删除</a-button>
                </a-form-item>
        </a-form>
         </div>
         
        <div>
            <compTable
             :key="compSelectorkey" 
             :config='dataTableConfig' 
             :columns="columns" 
             :requestParamObj="requestParams" 
             @selectedRowKeys="selectedRowKeys"
             @sorterChange="sorterChange"
             >
                <!-- <template v-slot:url="scope">
                    <span>{{ scope }}</span>
                </template> -->
                <template v-slot:operation="{record}" data-desc="自定操作栏">
                    <a-form layout="inline" class="search-form">
                        <a-form-item >
                            <a-button class="blue-btn" type="primary" @click="reviseClick(record)">编辑</a-button>
                        </a-form-item>
                        <a-form-item >
                            <a-button class="red-btn" type="primary" @click="deleteClick(record)" >删除</a-button>
                        </a-form-item>
                        <a-form-item >
                            <a-button class="blue-btn" type="primary" @click="detailedClick(record)" >详情</a-button>
                        </a-form-item>
                        <a-form-item >
                            <a-button class="blue-btn" type="primary" @click="shareTestPaperClick(record)" >分享试卷</a-button>
                        </a-form-item>
                        <a-form-item >
                            <a-button class="blue-btn" type="primary" @click="copyPaperClick(record)" >复制试卷</a-button>
                        </a-form-item>
                    </a-form>
                </template>
            </compTable>
        </div>
        <!-- <a-modal
         :visible="addEditVisible" 
         :title="addEditParameter.id?'编辑':'新增'" 
         @ok="handleOk" 
         :confirmLoading="confirmLoading" 
         @cancel="visible = false"> -->

         <increase ref="refModel" :addEditParameter="addEditParameter" @handleOk="handleOk" :fsjid="fsjid"/>
        <testPaperDetailed ref="refDetailed" :detailFsjid="detailFsjid"/>
        <QRCodeIncrease ref="QRCodeRef" :addEditParameter="addEditParameter"/>
        <copyPaper ref="copyPaperRef"  @AddHandleOk="AddHandleOk" :fsjid="copyFsjid"/>
        <!-- </a-modal> -->
        
    </div>
</template>
<script>
import compSearchCriteria from '@/components/compSearchCriteria/compSearchCriteria'
import compTable from '@/components/compTable/compTable'
import {typeInput, typeNumber, typeSelect, typeCheckbox, typeRadio} from '@/components/compSearchCriteria/ContractType'
import assessCheckApi from './service/api.js'
import increase from './increase.vue'
import { deleteArrServe, leadingInExccel, leadingOutExccel, leadingOutFormwork, spcyPxSjjbxxcopySj, } from './service/index'
import Vue from 'vue'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import testPaperDetailed from './testPaperDetailed.vue'
import QRCodeIncrease from './QRCodeIncrease.vue'
import copyPaper from './copyPaper.vue'
// import { CodeSandboxCircleFill } from '@yuncheng/ych-components'
  export default {
    components:{
        compSearchCriteria,
        compTable,
        increase,
        testPaperDetailed,
        QRCodeIncrease,
        copyPaper,
    },
    
    data(){
        return{
            addEditParameter:{},
            addEditVisible:false,
            selectedRowKeysArr:[],//选中表格数据
            compSelectorkey:'',
            requestParams:{},
            formItem:[
                {
                    label: '试卷名称',
                    model: 'fsjmc',
                },{
                    label: '试卷类型',
                    model: 'fsjlx',
                }

            ],
            columns: [
                {
                    title: '试卷名称', //列头显示文字
                    dataIndex: 'fsjmc',
                    key: 'fsjmc',
                },{
                    title: '试卷类型', //列头显示文字
                    dataIndex: 'fsjlx',
                    key: 'fsjlx',
                },{
                    title: '操作',
                    dataIndex: 'id',
                    fixed: 'right',
                    width:380,
                    scopedSlots: {customRender: 'operation'}, // 自定插槽格式
                }
            ],
            dataTableConfig:{
                api: assessCheckApi.list,
                rowKey: 'id',
                rowName: 'fsjmc',
                rowSelection: {
                    // selectedRowKeys: null,
                    // type: EselectionType.checkbox
                },
                fywflcode:'001002',
            },
            leadingOutLoading:false,
            DownloadTemplateLoading:false,
            fsjid:'',
            detailFsjid:'',
            copyFsjid:'',
        }
    },
    
    methods:{
        sorterChange(val,sorter){//获取到排序的数据
            //console.log('获取到排序的数据',val,sorter)
        },
        renovateSearchTabel(){//刷新搜索、表格
            this.compSelectorkey = Date.now()
            this.$refs.refSearchCriteria.resetEvents()
        },
        searchHandleChange(val){//获取搜索数据
            if(val.resetEvents){
                this.compSelectorkey = Date.now()
            }
            this.dataTableConfig.requestParams={...val}
            this.requestParams = {...this.requestParams,...val}
        },
        selectedRowKeys(keys){//获取选中表格rowKey
            this.selectedRowKeysArr = keys
        },
        increaseClick(){//新增
            this.$refs.refModel.visibleShow = true
            this.addEditParameter = {}
            this.$refs.refModel.getData()
            this.fsjid = ''
        },
        batchDeletion(){//
            var that = this
            this.$confirm({
                title:'您确认要删除吗？',
                // icon: createVNode(ExclamationCircleOutlined),
                onOk() {
                    if(that.selectedRowKeysArr.length){
                        let deleteString = that.selectedRowKeysArr.join(',')
                        deleteArrServe({ids:deleteString}).then(res=>{
                            if(res.code == 200){
                                that.$message.success('删除成功')
                            }else{
                                that.$message.warning(res.message)
                            }              
                            that.renovateSearchTabel()
                        })
                    }else{
                        that.$message.warning('请选择删除项')
                    }
                },
                
            });
            
            
        },
        handleOk(val,id){
            if(val && !id){
                this.renovateSearchTabel()
                this.fsjid=''
            }else if(val && id){
                this.requestParams = {
                    ...this.requestParams,
                    renovate:true,
                }
            }
            
        },
        //编辑
        reviseClick(val){
            //console.log('编辑',val[0])
            this.addEditParameter = val[0]
            this.fsjid = val[0].id
            this.$refs.refModel.getData(val[0])
            this.$refs.refModel.visibleShow = true
        },
        //删除
        deleteClick(val){
            var that = this
            this.$confirm({
                title:'您确认要删除吗？',
                // icon: createVNode(ExclamationCircleOutlined),
                onOk() {
                    deleteArrServe({ids:val[0].id}).then(res=>{
                        if(res.code == 200){
                            that.$message.success('删除成功')
                        }else{
                            that.$message.warning(res.message)
                        }              
                        that.renovateSearchTabel()
                    })
                },
                
            });
            
            
        },
        AddHandleOk(){
            this.renovateSearchTabel()
        },
        detailedClick(val){//详情
            //console.log('查看详情',val)
            this.detailFsjid = ''
            this.detailFsjid = val[0].id
            this.$refs.refDetailed.visibleDetailedShow = true
            this.$refs.refDetailed.getData(val[0])
        },
        shareTestPaperClick(val){//分享试卷
            this.addEditParameter= val[0]
            this.$refs.QRCodeRef.visibleQRCode = true
        },
        copyPaperClick(val){
            this.copyFsjid = val[0].id
            this.$refs.copyPaperRef.visibleShow = true
            this.$refs.copyPaperRef.getData(val[0])
        },
    },

  }
</script>
<style scoped>
.observer-lbrary-pages{
    background: #fff;
}
.btn-box{
    display: flex;
    justify-content: space-between;
}
.blue-btn{
    border: 1px solid #5ca3e5 !important;
    background-color: #5ca3e5 !important;
    color: #fff !important;
}
.red-btn{
    border: 1px solid #ed5565 !important;
    background-color: #ed5565 !important;
}

</style>